package Com.javaserver.servlet;


import Com.javaserver.bean.train;

import Com.javaserver.dao.trainserver;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/deletrain")
public class traindeletserverlet extends HttpServlet {
    trainserver tra = new trainserver();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

//培训的删除接口
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        Integer ddelete = Integer.parseInt(req.getParameter("delete"));
        train traind = new train();
        traind.setT_id(ddelete);

        trainserver tra = new trainserver();
        if (!tra.deletrain(traind)) {
            req.getSession().setAttribute("msg", "删除失败");
            resp.sendRedirect(req.getContextPath() + "/tralist");
        } else {
            List<train> list = tra.tralist(1);
            System.out.println(list);
            req.getSession().setAttribute("tralist", list);
            req.getSession().setAttribute("msg", "删除成功");
            resp.sendRedirect(req.getContextPath() + "/tralist");
        }
    }
}